import React, {useState, useEffect} from 'react';
import {connect} from 'dva';
import { useUpdateEffect } from '@umijs/hooks';
import {
  Tooltip,
  Row,
  Col,
  Card,
  Form,
  Input,
  Button,
  Modal,
  Tree
} from 'antd';
import dynamic from 'umi/dynamic';
import LoadingComponent from '@/components/PageLoading/index';
import SlickTable from '@/components/SlickTable';
import useSlickTable from '@/hooks/useSlickTable';
import request from '@/utils/request';

const {DirectoryTree} = Tree;

const namespace = 'flowTacheConfig';

// 判断空对象
const isEmptyObject = obj => {
  if (Object.keys(obj).length === 0) {
    return true;
  }
  return false;
};

function FlowCatalogTree(props) {

  const [treeData, setTreeDate] = useState([]);

  useEffect(() => {
    const tempTreeData = [
      {"id":1582815826548,"title":"项目中心","type":1,"systemCode":"BPC","iconCls":"catalog-close","state":"closed","children":[{"id":1582815836253,"title":"项目立项","type":1,"systemCode":"BPC","iconCls":"catalog-close"},{"id":1584000974110,"title":"项目建设","type":1,"systemCode":"BPC","iconCls":"catalog-close"},{"id":1584001001432,"title":"项目采购","type":1,"systemCode":"BPC","iconCls":"catalog-close"},{"id":1585039595380,"title":"售前支撑","type":1,"systemCode":"BPC","iconCls":"catalog-close"},{"id":1585298989319,"title":"项目立项与建设","type":1,"systemCode":"BPC","iconCls":"catalog-close"},{"id":1588215263168,"title":"售中售后支撑","type":1,"systemCode":"BPC","iconCls":"catalog-close","state":"closed","children":[{"id":1588215313889,"title":"故障申请单","type":1,"systemCode":"BPC","iconCls":"catalog-close"},{"id":1588237434399,"title":"问题申请单","type":1,"systemCode":"BPC","iconCls":"catalog-close"},{"id":1588502456830,"title":"结算申请单","type":1,"systemCode":"BPC","iconCls":"catalog-close"},{"id":1588836672560,"title":"功能开发及配置需求申请单","type":1,"systemCode":"BPC","iconCls":"catalog-close"}]},{"id":1588835867729,"title":"日常工作支撑","type":1,"systemCode":"BPC","iconCls":"catalog-close","state":"closed","children":[{"id":1588835887169,"title":"日常工作联络单","type":1,"systemCode":"BPC","iconCls":"catalog-close"},{"id":1590664099029,"title":"商机分享申请单","type":1,"systemCode":"BPC","iconCls":"catalog-close"}]},{"id":1589706273021,"title":"收入计划变更","type":1,"systemCode":"BPC","iconCls":"catalog-close"},{"id":1589790819987,"title":"收支填报申请单","type":1,"systemCode":"BPC","iconCls":"catalog-close"}]},{"id":1591149703285,"title":"hh","type":1,"systemCode":"BPC","iconCls":"catalog-close","state":"closed","children":[{"id":1591149714248,"title":"1","type":1,"systemCode":"BPC","iconCls":"catalog-close"}]}
    ];
    // request('/project/OrderFlowExecController/modifyOrderFlowExec.do',{
    //   data: submintData
    // }).then(res => {
    //   if (res.resultCode && res.resultCode === 'TRUE') {
    //       // props.setUrgeTimeCfgFlag(false);
    //       props.handleDealModeCallBack(false);
    //   } else {
    //     info({title: "提交失败", content: (res.resultMsg)});
    //   }
    // });
    setTreeDate(tempTreeData);
  },[]);

  // 通过dva存当前需要传递的数据
  const saveSelectCatalog = params => {
    const {dispatch} = props;
    dispatch({
      type: `${namespace}/saveSelectCatalog`,
      payload: params,
    });
  };

  const onSelect = (record, e) => {
    saveSelectCatalog(record);
  }

  const onExpand = record => {

  }

  return (
    <DirectoryTree
      multiple
      defaultExpandAll
      onSelect={onSelect}
      onExpand={onExpand}
      treeData={treeData}
    />
  );

}

export default connect(({flowTacheConfig,setting}) => ({
  selectRecord: flowTacheConfig.selectRecord,
  size: setting.size
}))(Form.create()(FlowCatalogTree));
